<html>
<head><meta charset="utf-8"><title>code generation · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/code.20generation.html">code generation</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="176527702"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/code%20generation/near/176527702" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Leo Le Bouter <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/code.20generation.html#176527702">(Sep 25 2019 at 02:20)</a>:</h4>
<p>is it a design goal for rls to be abused as a code generator through it's autocomplete support?</p>



<a name="176527773"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/code%20generation/near/176527773" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Leo Le Bouter <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/code.20generation.html#176527773">(Sep 25 2019 at 02:22)</a>:</h4>
<p>e.g. selecting a random element from the autocomplete list including any snippet such as for loop or if conditions then filling in random parameters, would rls offer completion when it knows using some variable wouldnt violate borrow checking for example?</p>



<a name="176527801"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/code%20generation/near/176527801" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Leo Le Bouter <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/code.20generation.html#176527801">(Sep 25 2019 at 02:23)</a>:</h4>
<p>I assume that has to be resource hungry to somehow check every variable currently in scope for possible borrow checking violations and filter out the ones that will</p>



<a name="176527863"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/code%20generation/near/176527863" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Leo Le Bouter <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/code.20generation.html#176527863">(Sep 25 2019 at 02:25)</a>:</h4>
<p>I want to make a valid Rust random code generator</p>



<a name="176537395"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/code%20generation/near/176537395" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/code.20generation.html#176537395">(Sep 25 2019 at 06:32)</a>:</h4>
<p>By code generator you mean <em>source</em> code generator (as opposed to machine code generator)?</p>



<a name="176537400"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/code%20generation/near/176537400" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/code.20generation.html#176537400">(Sep 25 2019 at 06:32)</a>:</h4>
<p>rust-analyzer already have some facilities to generate source code, and the'll grow in the future</p>



<a name="176537404"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/code%20generation/near/176537404" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/code.20generation.html#176537404">(Sep 25 2019 at 06:32)</a>:</h4>
<p>See the <code>AstBuilder</code>, <code>AstEditor</code> types</p>



<a name="176547075"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/code%20generation/near/176547075" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/code.20generation.html#176547075">(Sep 25 2019 at 09:18)</a>:</h4>
<p>I think it's unlikely that we would hide completions if they e.g. violate borrow checking, even if we could do that (which we are a long way from). It's surprising, and often the desired fix would actually be elsewhere</p>



<a name="176579010"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/code%20generation/near/176579010" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Leo Le Bouter <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/code.20generation.html#176579010">(Sep 25 2019 at 15:55)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> Yes, that's what I mean. Thank you, I'll have a look, though, all the challenge is into making valid generation choices, even with access to an AST.<br>
<span class="user-mention" data-user-id="129457">@Florian Diebold</span> Okay. Thanks.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>